// 回文 p231 15-2
use std::cmp;
pub fn palindrom(str:&Vec<char>)->i32{
    bottom(str)
    //palindrom_inter(str)
}
// 从顶到底
fn palindrom_inter(str:&Vec<char>)->i32{
    fn inter(str:&Vec<char>,i:usize,j:usize)->i32{
        if i == j {
            return 1
        }
        if j == i+1{
            if str[i] == str[j] {
                return 2
            }
            return 1
        }
        if str[i] == str[j]{
            return inter (str,i+1,j-1)+2;
        }
        return cmp::max(inter(str,i+1,j),inter(str,i,j-1));
    }
    inter(str,0,str.len()-1)
}
// 从底到顶
fn bottom(str:&Vec<char>)->i32{
    let mut count = 0;
    let mut index = 0;
    for i in 0..str.len() {
        for j in 0..(i-count+1){
            if(str[i]==str[j]){
                if(i==j){
                    count = 1;
                    index = j;
                    break;
                }else if i==j+1{
                    count = count+1;
                    index = j;
                    break;
                }else{
                    if(index > j){
                        count =count +2;
                    }else{
                        count = cmp::max((bottom(&str[j+1..i].to_vec())+2) as usize,count);
                    }
                    break;
                }
            }
        }
    }
    return count as i32;
}
